﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.TrainUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class TrainStopCell extends DataItemCell {

        public static const CELL_WIDTH:Number = 66;
        public static const CELL_HEIGHT:Number = 170;
        public static const CARD_WIDTH:Number = 66;
        public static const CARD_HEIGHT:Number = 129;

        private var m_cellData:Object;
        private var m_portraitPanel:JPanel;
        private var m_portrait:DisplayObject;
        private var m_friend:Player;

        public function TrainStopCell(_arg1:LayoutManager=null){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS));
        }
        public function get friend():Player{
            return (this.m_friend);
        }
        override protected function initializeCell():void{
            var _local9:String;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            this.setupBackground(_local1);
            if (!this.m_portrait){
                if (this.m_cellData.hasOwnProperty("uid")){
                    this.m_friend = Global.player.findFriendById(this.m_cellData["uid"]);
                    if (this.m_friend){
                        _local9 = this.m_friend.snUser.picture;
                        this.m_portrait = LoadingManager.loadFromUrl(_local9, {
                            priority:LoadingManager.PRIORITY_LOW,
                            completeCallback:this.onLoadPicSuccess
                        });
                        (this.m_portrait as Loader).contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onLoadPicFail, false, 2);
                    } else {
                        this.m_portrait = new (TrainStationDialog.assetDict["portrait_empty"])();
                    };
                } else {
                    this.m_portrait = new (TrainStationDialog.assetDict["portrait_empty"])();
                };
            };
            var _local2:AssetPane = new AssetPane(this.m_portrait);
            this.m_portraitPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_portraitPanel.setPreferredHeight(50);
            this.m_portraitPanel.append(_local2);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local3.append(new AssetPane(new (TrainStationDialog.assetDict["checkmark"])()));
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local5:DisplayObject = ((this.m_cellData["commodityType"] == "goods")) ? new (TrainStationDialog.assetDict["crate_small"])() : new (TrainStationDialog.assetDict["coin_small"])();
            _local4.append(new AssetPane(_local5));
            var _local6:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local6.append(ASwingHelper.makeTextField(this.m_cellData["commodityIncrement"], EmbeddedArt.TITLE_FONT, 20, EmbeddedArt.greenTextColor));
            var _local7:JPanel = ASwingHelper.makeSoftBoxJPanelVertical();
            _local7.appendAll(_local4, _local6);
            _local1.appendAll(ASwingHelper.verticalStrut(5), this.m_portraitPanel, ASwingHelper.verticalStrut(5), (this.m_cellData.hasOwnProperty("uid")) ? _local3 : _local7);
            var _local8:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local8.append(ASwingHelper.makeTextField((m_index + 1).toString(), EmbeddedArt.TITLE_FONT, 30, EmbeddedArt.blueTextColor));
            removeAll();
            appendAll(_local1, ASwingHelper.verticalStrut(-5), _local8);
            ASwingHelper.prepare(this);
        }
        private function onLoadPicSuccess(_arg1):void{
            ASwingHelper.prepare(this);
        }
        private function onLoadPicFail(_arg1:Event):void{
            ASwingHelper.prepare(this);
        }
        protected function setupBackground(_arg1:JPanel):void{
            var _local2:Class = TrainStationDialog.assetDict["portrait_card"];
            var _local3:DisplayObject = new (_local2)();
            var _local4:AssetBackground = new AssetBackground(_local3);
            _arg1.setBackgroundDecorator(_local4);
            _arg1.setPreferredSize(new IntDimension(CELL_WIDTH, CARD_HEIGHT));
        }
        override public function setCellValue(_arg1):void{
            this.m_cellData = _arg1;
            this.setGridListCellStatus(m_gridList, false, m_index);
        }
        override public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
            super.setGridListCellStatus(_arg1, _arg2, _arg3);
            this.initializeCell();
        }
        override public function getCellValue(){
            return (this.m_cellData);
        }

    }
}//package Display.TrainUI 
